//065959264	Limor Bagizada	040199770	Sarit Chicotay

package General;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
 * 
 * DocumentReader class contains static method for manipulating files content.
 *
 */
public class DataReader {
	
	/**
	 * Reads the content of the articles files (derived from Reuters-21578 corpus) 
	 * @param filename - the file containing the articles
	 * @return - array of all words in the file (referring only to the articles' content, i.e. every even line in the file)
	 * @throws IOException
	 */
	 public static ArrayList<String> ReadArticles(String filename) throws IOException{	
		ArrayList<String> content = new ArrayList<String>(); // list of the articles' words
		BufferedReader input = null; // used for reading input file content
		String line = null; // represent a single line content
		
		// initialize reader
		FileReader reader = new FileReader(filename);
		input =  new BufferedReader(reader);
 
		// line counter
		int num = 0;		
        while((line = input.readLine()) != null)
        {
        	num++;
        	
        	// only even lines in the file contains the articles' content
        	if (num % 2 != 0)
        		continue;
        	
        	// split line to words (events)
        	String[] words = line.split(" ");
        	for (String word : words)
        	{
        		// add words to the content list
        		if (word.trim() != "")
        			content.add(word);
        	}     	
        }
        
        return content;
        	
	 }
	 
}
